package com.jiayinlending.jiayindai.activity.login;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.jiayinlending.jiayindai.R;
import com.jiayinlending.jiayindai.activity.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.jiayinlending.jiayindai.R.id.bt_get;

public class FindPasswordActivity extends BaseActivity{
    @Bind(R.id.et_regnumber)
    EditText et_regnumber;
    @Bind(R.id.et_yanzhengma)
    EditText etYanzhengma;
    @Bind(bt_get)
    Button btGet;
    @Bind(R.id.bt_next)
    Button btNext;
    private TimeCount time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        getToolbarTitle().setText("找回密码");
        getSubTitle().setText("");
        time = new TimeCount(60000, 1000);//构造CountDownTimer对象
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_findpassword;
    }


    @OnClick({R.id.et_regnumber, R.id.et_yanzhengma, bt_get, R.id.bt_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.et_resnum:
                break;
            case R.id.et_yanzhengma:
                break;
            case bt_get:
                time.start();
                btGet.setBackgroundColor(Color.parseColor("#CCCCCC"));
                break;
            case R.id.bt_next:
                startActivity(new Intent(FindPasswordActivity.this, ResettingActivity.class));
                finish();
                break;
        }
    }

    /* 定义一个倒计时的内部类 */
    class TimeCount extends CountDownTimer {
        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
        }

        @Override
        public void onFinish() {//计时完毕时触发
            btGet.setText("重新验证");
            btGet.setClickable(true);
        }

        @Override
        public void onTick(long millisUntilFinished) {//计时过程显示
            btGet.setClickable(false);
            btGet.setText(millisUntilFinished / 1000 + "秒");
        }
    }
}
